/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__req_data_analysis.c                             */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/31 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include <mongodb/mongodb_core.h>
#include "frsutl.h"
#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "frreport_comm.h"
#include "../../../src/module/mongodb/config.h"
#include "frbyte_buffer.h"
#include "apmtest_cunit.h"

typedef struct __st_L7session_mongodb_private
{
    unsigned long ul_seq;                             /*!< 序列号，1次req和response时，使用同一个序列号 */
    L4_transaction st_l4_trans;                       /*!< 数据 */
    Frreport_body_data *p_st_body_data_req;
    Frreport_body_data *p_st_body_data_resp;
    Frlist_header *p_lst_comm;
    Frlist_header *p_lst_req;
    Frbyte_Packet *p_req_packet;                      /*!< 存请求bytebuff数据 */
    Frbyte_Packet *p_resp_packet;                     /*!< 存相应bytebuff数据 */
    int i_len;                                        /*!< 数据总长度 */
    int i_req_doc_len;                                /*!< documents长度 */
    int i_resp_doc_len;                               /*!< documents长度 */
    int i_sign;                                       /*!< 标记位 */
}L7session_mongodb_private;

extern L7session_mongodb_private* __mongodb_private_create(void);
extern int __req_data_analysis(Conntrack *p_st_conn
                                , Apm_packet *p_st_data_in
                                , Frhash_header *p_st_hash_report
                                , L7_session *p_st_session);
extern int mongodb_session_destroy(void *p_private_session);
extern void list_report_node_free(Frlist_node *p_st_node);

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void case1(void)
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    Frhash_header *p_st_hash_report = NULL;
    L7_session *p_st_session = NULL;
    
    i_ret = __req_data_analysis(p_st_conn, p_st_packet, p_st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);
    CU_ASSERT_PTR_EQUAL(p_st_session, NULL);

    return;
}

static void case2(void)//2004
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x3a\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xd4\x07\x00\x00\x00\x00\x00\x00\x61\x64\x6d\x69\x6e\x2e\x24\x63\x6d\x64\x00\x00\x00\x00\x00\xff\xff\xff\xff\x13\x00\x00\x00\x10\x69\x73\x6d\x61\x73\x74\x65\x72\x00\x01\x00\x00\x00\x00";
    p_st_packet->ui_payload_len = 58;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 58);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case3(void)//2002
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x52\x00\x00\x00\x05\x65\xd5\xb3\xff\xff\xff\xff\xd2\x07\x00\x00\x00\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x2e\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x2a\x00\x00\x00\x07\x5f\x69\x64\x00\x4c\xc9\x96\xa4\x4d\x4c\x0c\xd4\xd2\xe4\x6b\xd2\x02\x6e\x61\x6d\x65\x00\x0a\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x00";
    p_st_packet->ui_payload_len = 82;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 82);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case4(void)//2001
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x58\x00\x00\x00\xe1\x69\xd5\xb3\xff\xff\xff\xff\xd1\x07\x00\x00\x00\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x2e\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x01\x00\x00\x00\x19\x00\x00\x00\x02\x6e\x61\x6d\x65\x00\x0a\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x00\x13\x00\x00\x00\x02\x6e\x61\x6d\x65\x00\x04\x00\x00\x00\x65\x6e\x64\x00\x00";
    p_st_packet->ui_payload_len = 88;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 88);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case5(void)//2005
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x34\x00\x00\x00\xdc\x69\xd5\xb3\xff\xff\xff\xff\xd5\x07\x00\x00\x00\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x2e\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x00\x00\x00\x00\x13\x76\x74\xa5\x57\x23\xa8\x77";
    p_st_packet->ui_payload_len = 52;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 52);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case6(void)//2006
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x31\x00\x00\x00\xe3\x69\xd5\xb3\xff\xff\xff\xff\xd6\x07\x00\x00\x00\x00\x00\x00\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x2e\x77\x69\x72\x65\x73\x68\x61\x72\x6b\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00";
    p_st_packet->ui_payload_len = 52;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 52);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case7(void)//2007
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x20\x00\x00\x00\xe6\x69\xd5\xb3\xff\xff\xff\xff\xd7\x07\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xfa\x75\x74\xa5\x07\xaa\xbd\x10";
    p_st_packet->ui_payload_len = 32;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 32);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case8(void)//2007拆分成两段
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x20\x00\x00\x00\xe6\x69\xd5\xb3\xff\xff\xff\xff\xd7\x07\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xfa\x75\x74\xa5\x07\xaa\xbd";
    p_st_packet->ui_payload_len = 31;
    p_st_packet->st_timestamp.tv_sec = 11;
    p_st_packet->st_timestamp.tv_usec = 22;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 31);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 22);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

static void case9(void)//2007拆分成两段
{
    int i_ret = 0;
    Conntrack *p_st_conn = NULL;
    Apm_packet *p_st_packet = NULL;
    L7_session *p_st_session = NULL;
    char *p_data = NULL;
    L7session_mongodb_private *p_st_private = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    L4_transaction *p_st_l4_trans = NULL;
    Frhash_header st_hash_report;
    frhash2_create(&st_hash_report, 2);

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    if(p_st_conn == NULL)
        goto ERROR;
    memset(p_st_conn, 0x00, sizeof(Conntrack));
    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;

    p_st_packet = (Apm_packet *)frmalloc(sizeof(Apm_packet));
    if(p_st_packet == NULL)
        goto ERROR;
    memset(p_st_packet, 0x00, sizeof(Apm_packet));
    p_st_packet->p_payload = (char *)"\x10";
    p_st_packet->ui_payload_len = 1;
    p_st_packet->st_timestamp.tv_sec = 33;
    p_st_packet->st_timestamp.tv_usec = 44;

    p_st_session = (L7_session *)frmalloc(sizeof(L7_session));
    if(p_st_session == NULL)
        goto ERROR;
    memset(p_st_session, 0x00, sizeof(L7_session));
    p_st_session->p_session_private = __mongodb_private_create();
    if(p_st_session->p_session_private == NULL)
        goto ERROR;

    p_data = (char *)"\x20\x00\x00\x00\xe6\x69\xd5\xb3\xff\xff\xff\xff\xd7\x07\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\xfa\x75\x74\xa5\x07\xaa\xbd";
    p_st_private = (L7session_mongodb_private *)p_st_session->p_session_private;
    p_st_private->p_req_packet = bytebuff_creat();
    if(p_st_private->p_req_packet == NULL)
        goto ERROR;
    if(bytebuff_add(p_st_private->p_req_packet, p_data, 31) != FR_SUCC)
        goto ERROR;
    p_st_private->i_len = 32;
    p_st_l4_trans = &(p_st_private->st_l4_trans);
    p_st_l4_trans->l_request_bytes = 31;
    p_st_l4_trans->st_request_time_first_byte.tv_sec = 11;
    p_st_l4_trans->st_request_time_first_byte.tv_usec = 22;
    p_st_private->p_st_body_data_req = (Frreport_body_data *)frmalloc(sizeof(Frreport_body_data));
    if(p_st_private->p_st_body_data_req == NULL)
        goto ERROR;
    memset(p_st_private->p_st_body_data_req, 0x00, sizeof(Frreport_body_data));
    p_st_body_data = p_st_private->p_st_body_data_req;
    p_st_body_data->em_type = FRREPORT_TYPE_L7DATA;

    i_ret = __req_data_analysis(p_st_conn, p_st_packet, &st_hash_report, p_st_session);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SET_REQ(APM_L7_ANALYZE_SUCC));
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.l_request_bytes, 32);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_sec, 11);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time_first_byte.tv_usec, 22);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_sec, 33);
//    CU_ASSERT_EQUAL(((L7session_mongodb_private *)(p_st_session->p_session_private))->st_l4_trans.st_request_time.tv_usec, 44);

    frfree(p_st_conn);
    frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    mongodb_session_destroy(p_st_session->p_session_private);
    frfree(p_st_session);

    return;

ERROR:
    if(p_st_conn)
        frfree(p_st_conn);
    if(p_st_packet)
        frfree(p_st_packet);
    frhash2_free(&st_hash_report, list_report_node_free);
    if(p_st_session)
    {
        if(p_st_session->p_session_private)
            mongodb_session_destroy(p_st_session->p_session_private);
        frfree(p_st_session);
    }

    return;
}

int add_suite__req_data_analysis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __req_data_analysis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL ||
        CU_add_test(pSuite, "case2", case2) == NULL ||
        CU_add_test(pSuite, "case3", case3) == NULL ||
        CU_add_test(pSuite, "case4", case4) == NULL ||
        CU_add_test(pSuite, "case5", case5) == NULL ||
        CU_add_test(pSuite, "case6", case6) == NULL ||
        CU_add_test(pSuite, "case7", case7) == NULL ||
        CU_add_test(pSuite, "case8", case8) == NULL ||
        CU_add_test(pSuite, "case9", case9) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}